/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RelatoView.java
 *
 * Created on 14/10/2011, 03:44:43
 */
package br.com.geftu.view;

import br.com.geftu.util.Anexar;
import br.com.geftu.HibernateUtil.HibernateUtil;
import br.com.geftu.controle.ArrayListComboBoxModel;
import br.com.geftu.dao.DAO;
import br.com.geftu.model.Anexo;
import br.com.geftu.model.Categoria;
import br.com.geftu.model.Desenvolvedor;
import br.com.geftu.model.Modulo;
import br.com.geftu.model.Participa;
import br.com.geftu.model.Projeto;
import br.com.geftu.model.Relato;
import com.towel.el.annotation.AnnotationResolver;
import com.towel.swing.table.ObjectTableModel;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;

/**
 *
 * @author jorgenei
 */
public final class RelatoView extends javax.swing.JFrame implements ActionListener {

    private JPopupMenu popupMenu;
    LoginView login = new LoginView();
    private JMenuItem menuItemView;
    private JMenuItem menuItemRemove;
    List<Projeto> lista_projeto = new ArrayList();
    List<Modulo> lista_modulo = new ArrayList();
    List<Relato> lista_relato = new ArrayList();
    List<Desenvolvedor> lista_desenvolvedor = new ArrayList();
    Projeto projetosel = new Projeto();
    ObjectTableModel<Relato> modelrel = new ObjectTableModel<Relato>(
            new AnnotationResolver(Relato.class), "idrel:ID,modulo.projeto:Projeto,modulo.modulo:Módulo,desenvolvedor.nome:Desenvolvedor,categoriaerro.categoria:Categoria do Erro,nomeobjeto:Objeto,dtabertura:Data de Abertura");
    ObjectTableModel<Anexo> modelanx = new ObjectTableModel<Anexo>(
            new AnnotationResolver(Anexo.class), "idanx:ID,caminho:Arquivo");

    /**
     * Creates new form Menu
     */
    public RelatoView() {
        initComponents();
        popularComboProj();
        preencherJtableRelatos();
        desativaBotoes();
        this.setTitle("CONTROLE DE RELATOS DE DEFEITOS - Você está logado como: " + login.d.getNome());
    }

    /**
     * This method is called from within the constructor to initialize the
     * form.. WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDesktopPane1 = new javax.swing.JDesktopPane();
        jPanel_Menu = new javax.swing.JPanel();
        btNovo = new javax.swing.JButton();
        btSalvar = new javax.swing.JButton();
        btExcluir = new javax.swing.JButton();
        cb_selecProjeto = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        btTodos = new javax.swing.JButton();
        btAbrir = new javax.swing.JButton();
        btAnexar = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtab_Relatos = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtab_Anexos = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        Painel_incluirRelato = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        tf_Relato = new javax.swing.JTextField();
        cb_categoria = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        cb_status = new javax.swing.JComboBox();
        tf_classeObjeto = new javax.swing.JTextField();
        tf_DTAbertura = new javax.swing.JTextField();
        tf_DTFech = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        tf_codigo = new javax.swing.JTextField();
        cb_modulo = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        tf_casoTeste = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        tf_passos = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        lb_desenvolvedor = new javax.swing.JLabel();
        cb_desenvolvedor = new javax.swing.JComboBox();
        cb_prioridade = new javax.swing.JComboBox();
        jLabel13 = new javax.swing.JLabel();
        lb_Relato = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        lb_solucao = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenu3 = new javax.swing.JMenu();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenu5 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("GEFTU - Gerência de Defeitos para Teste Unitário");
        getContentPane().setLayout(null);

        jPanel_Menu.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        btNovo.setText("Novo");
        btNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btNovoActionPerformed(evt);
            }
        });

        btSalvar.setText("Salvar");
        btSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSalvarActionPerformed(evt);
            }
        });

        btExcluir.setText("Excluir");
        btExcluir.setToolTipText("");

        cb_selecProjeto.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "<<Todos>>" }));
        cb_selecProjeto.setSelectedIndex(-1);
        cb_selecProjeto.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cb_selecProjetoItemStateChanged(evt);
            }
        });

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel1.setText("Projeto:");

        btTodos.setText("Exibir Todos");
        btTodos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTodosActionPerformed(evt);
            }
        });

        btAbrir.setText("Abrir");

        btAnexar.setText("Anexar DOC");

        jButton4.setText("Fechar");

        javax.swing.GroupLayout jPanel_MenuLayout = new javax.swing.GroupLayout(jPanel_Menu);
        jPanel_Menu.setLayout(jPanel_MenuLayout);
        jPanel_MenuLayout.setHorizontalGroup(
            jPanel_MenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_MenuLayout.createSequentialGroup()
                .addComponent(btNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btAbrir, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btExcluir, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btAnexar)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cb_selecProjeto, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btTodos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(264, Short.MAX_VALUE))
        );
        jPanel_MenuLayout.setVerticalGroup(
            jPanel_MenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel_MenuLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(btNovo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btAbrir)
                .addComponent(btSalvar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btExcluir, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addComponent(cb_selecProjeto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(btTodos)
                .addComponent(btAnexar)
                .addComponent(jButton4))
        );

        jScrollPane1.setSize(500, 800);

        jtab_Relatos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jtab_Relatos.setPreferredSize(new java.awt.Dimension(200, 64));
        jtab_Relatos.setSize(800, 800);
        jtab_Relatos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtab_RelatosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jtab_Relatos);

        jTabbedPane1.addTab("Relatos", jScrollPane1);

        jtab_Anexos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane2.setViewportView(jtab_Anexos);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(500, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Anexos", jPanel1);

        Painel_incluirRelato.setVisible(false);

        jLabel2.setText("Classe/Objeto:");

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText("Categoria Defeito:");

        jLabel6.setText("Situação:");

        cb_status.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Aberto", "Atribuído", "Congelado", "Duplicado", "Incompleto", "Não confirmado", "Reaberto", "Resolvido", "Fechado" }));
        cb_status.setAlignmentX(0.0F);
        cb_status.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cb_statusActionPerformed(evt);
            }
        });

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel7.setText("Data Abertura:");

        jLabel8.setText("Data Fechamento:");

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel9.setText("Código:");

        tf_codigo.setEnabled(false);
        tf_codigo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tf_codigoActionPerformed(evt);
            }
        });

        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText("Módulo:");

        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel11.setText("Caso de Teste:");

        jLabel12.setText("Passos Repetição:");

        lb_desenvolvedor.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lb_desenvolvedor.setText("Desenvolvedor:");

        jLabel13.setText("Prioridade:");

        lb_Relato.setText("Relato:");

        jTextField1.setText("jTextField1");

        lb_solucao.setText("Solução:");

        javax.swing.GroupLayout Painel_incluirRelatoLayout = new javax.swing.GroupLayout(Painel_incluirRelato);
        Painel_incluirRelato.setLayout(Painel_incluirRelatoLayout);
        Painel_incluirRelatoLayout.setHorizontalGroup(
            Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Painel_incluirRelatoLayout.createSequentialGroup()
                .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, Painel_incluirRelatoLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lb_Relato, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(lb_solucao, javax.swing.GroupLayout.Alignment.TRAILING))))
                .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Painel_incluirRelatoLayout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, Painel_incluirRelatoLayout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(Painel_incluirRelatoLayout.createSequentialGroup()
                                        .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
                                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(10, 10, 10)
                                        .addComponent(cb_modulo, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(86, 86, 86)
                                        .addComponent(jLabel2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(tf_classeObjeto, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(289, 289, 289))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, Painel_incluirRelatoLayout.createSequentialGroup()
                                        .addComponent(tf_casoTeste, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel12)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(tf_passos, javax.swing.GroupLayout.PREFERRED_SIZE, 516, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(182, 182, 182))))
                            .addGroup(Painel_incluirRelatoLayout.createSequentialGroup()
                                .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(tf_DTAbertura, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(Painel_incluirRelatoLayout.createSequentialGroup()
                                        .addComponent(cb_categoria, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(14, 14, 14)
                                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(cb_status, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(28, 28, 28)
                                        .addComponent(lb_desenvolvedor, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(9, 9, 9)
                                        .addComponent(cb_desenvolvedor, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(tf_Relato, javax.swing.GroupLayout.DEFAULT_SIZE, 826, Short.MAX_VALUE)
                                    .addComponent(jTextField1))
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(Painel_incluirRelatoLayout.createSequentialGroup()
                        .addGap(146, 146, 146)
                        .addComponent(jLabel8)
                        .addGap(3, 3, 3)
                        .addComponent(tf_DTFech, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)
                        .addComponent(jLabel13)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cb_prioridade, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );
        Painel_incluirRelatoLayout.setVerticalGroup(
            Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(Painel_incluirRelatoLayout.createSequentialGroup()
                .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(Painel_incluirRelatoLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel10)
                                .addComponent(cb_modulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel2)
                                .addComponent(tf_classeObjeto, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(tf_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9))
                        .addGap(12, 12, 12)
                        .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(tf_passos, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(tf_casoTeste, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(Painel_incluirRelatoLayout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cb_categoria, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(cb_status, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6)
                        .addComponent(lb_desenvolvedor)
                        .addComponent(cb_desenvolvedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(tf_DTAbertura, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tf_DTFech, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel13)
                        .addComponent(cb_prioridade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(tf_Relato, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lb_Relato))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(Painel_incluirRelatoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 64, Short.MAX_VALUE)
                    .addGroup(Painel_incluirRelatoLayout.createSequentialGroup()
                        .addComponent(lb_solucao)
                        .addGap(0, 0, Short.MAX_VALUE))))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Painel_incluirRelato, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(Painel_incluirRelato, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout jDesktopPane1Layout = new javax.swing.GroupLayout(jDesktopPane1);
        jDesktopPane1.setLayout(jDesktopPane1Layout);
        jDesktopPane1Layout.setHorizontalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDesktopPane1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel_Menu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 967, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jDesktopPane1Layout.setVerticalGroup(
            jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jDesktopPane1Layout.createSequentialGroup()
                .addComponent(jPanel_Menu, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jDesktopPane1.setLayer(jPanel_Menu, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jDesktopPane1.setLayer(jTabbedPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);
        jDesktopPane1.setLayer(jPanel2, javax.swing.JLayeredPane.DEFAULT_LAYER);

        getContentPane().add(jDesktopPane1);
        jDesktopPane1.setBounds(0, 0, 980, 585);

        jMenu1.setText("Arquivo");

        jMenuItem1.setText("Sair");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        jMenu3.setText("Cadastros");
        jMenu3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu3ActionPerformed(evt);
            }
        });

        jMenuItem6.setText("Categoria");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem6);

        jMenuItem2.setText("Desenvolvedor");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem2);

        jMenuItem5.setText("Função");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem5);

        jMenuItem4.setText("Participação");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem4);

        jMenuItem3.setText("Projeto");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem3);

        jMenuItem7.setText("Módulo");
        jMenuItem7.setToolTipText("");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuItem7);

        jMenuBar1.add(jMenu3);

        jMenu2.setText("Relatar");
        jMenuBar1.add(jMenu2);

        jMenu5.setText("Útil");
        jMenuBar1.add(jMenu5);

        jMenu4.setText("Ajuda");
        jMenuBar1.add(jMenu4);

        setJMenuBar(jMenuBar1);

        setSize(new java.awt.Dimension(1001, 555));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents
    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        String args[] = new String[1];
        args[0] = "Cadastro de Desenvolvedores";
        DesenvolvedorView.main(args);
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenu3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu3ActionPerformed
        new ProjetoView().setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_jMenu3ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        new FuncaoView().setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        new CategoriaView().setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed

        new ProjetoView().setVisible(true);        // TODO add your handling code here:// TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        System.exit(0);        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        new ParticipaView().setVisible(true);        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
        new ModuloView().setVisible(true);
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void btAnexarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAnexarActionPerformed
        // TODO add your handling code here:
        try {
            Anexar anexo = new Anexar();
            Relato relato = modelrel.getValue(jtab_Relatos.getSelectedRow()); //Linha do registro
            anexo.Anexar(relato);
            preencherJtableAnexos();
            jTabbedPane1.setSelectedIndex(1);
        } catch (HibernateException e) {
            JOptionPane.showMessageDialog(null, instance);
        }

    }//GEN-LAST:event_btAnexarActionPerformed

    private void btTodosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTodosActionPerformed
        // Exibir Todos os registros de Projetos na JTABLE:
        popularComboProj();
        popularCombobox();
        Painel_incluirRelato.setVisible(false);
        preencherJtableRelatos();
    }//GEN-LAST:event_btTodosActionPerformed

    private void cb_selecProjetoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cb_selecProjetoItemStateChanged
        projetosel = (Projeto) cb_selecProjeto.getSelectedItem();
        popularCombobox();
        preencherJtableRelatos();
        modelanx.clear();
        jTabbedPane1.setSelectedIndex(0);
        desativaBotoes();
        ativaBotNew();
        // TODO add your handling code here:
    }//GEN-LAST:event_cb_selecProjetoItemStateChanged

    private void jtab_RelatosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtab_RelatosMouseClicked
        // TODO add your handling code here:
        exibeOcultaCampos();
        limpaCampos();
        ativaBotExist();

        try {
            Relato relato = modelrel.getValue(jtab_Relatos.getSelectedRow()); //Linha do registro
            cb_selecProjeto.setSelectedItem(relato.getModulo().getProjeto());
            tf_codigo.setText(relato.getIdrel().toString());
            popularCombobox();

            cb_modulo.setSelectedItem(relato.getModulo());
            tf_casoTeste.setText(relato.getCasoteste());
            tf_passos.setText(relato.getPassos());
            tf_classeObjeto.setText(relato.getNomeobjeto());
            cb_prioridade.setSelectedItem(Integer.toString(relato.getPrioridade()));
            tf_Relato.setText(relato.getRelato());
            cb_categoria.setSelectedItem(relato.getCategoriaerro());
            cb_status.setSelectedItem(relato.getSituacao());
            cb_desenvolvedor.setSelectedItem(relato.getDesenvolvedor());
            tf_DTAbertura.setText(relato.getDtabertura());
            tf_DTFech.setText(relato.getDtfechamento());
        } catch (HeadlessException e) {
            JOptionPane.showMessageDialog(null, e.getCause());
        }

        preencherJtableAnexos();
    }//GEN-LAST:event_jtab_RelatosMouseClicked

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private void btSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSalvarActionPerformed
        //       Salva relato no banco de dados

        try {
            Session sessao = HibernateUtil.getSessionFactory().openSession();
            List<Participa> p;

            //Seleciona o gerente do projeto para incorporar no relato
            Criteria criteria = sessao.createCriteria(Participa.class);
            criteria.createAlias("desenvolvedor", "desenvolvedor");
            criteria.createAlias("projeto", "projeto");
            criteria.createAlias("funcao", "funcao");
            criteria.add(Restrictions.eq("projeto", cb_selecProjeto.getSelectedItem()));
            p = criteria.list();

            Desenvolvedor d = new Desenvolvedor();

            Relato relato = new Relato();
            //Cria novo relato no sistema
            if (tf_codigo.getText().equals("")) {
                relato.setModulo((Modulo) cb_modulo.getSelectedItem());
                relato.setNomeobjeto(tf_classeObjeto.getText());
                relato.setCasoteste(tf_casoTeste.getText());
                relato.setPassos(tf_passos.getText());
                relato.setRelato(tf_Relato.getText());

                relato.setPrioridade(Integer.parseInt(cb_prioridade.getSelectedItem().toString()));
                relato.setCategoriaerro((Categoria) cb_categoria.getSelectedItem());
                relato.setSituacao(cb_status.getSelectedItem().toString());
                //
                try {
                    boolean gerente = false;
                    for (Participa c : p) {
                        if (c.getFuncao().getIdfunc().equals(3)) {
                            d = c.getDesenvolvedor();
                            gerente = true;
                        }
                        if (gerente != true) {
                            d = c.getDesenvolvedor();
                        }
                    }
                } catch (HeadlessException e) {
                    System.out.println(e);
                }
                relato.setDesenvolvedor(d);
                relato.setDtabertura(tf_DTAbertura.getText());
                relato.setDtfechamento(tf_DTFech.getText());

                DAO objrelato = new DAO(relato);
                objrelato.insere();
                preencherJtableRelatos();
            } else {
                //Altera novo relato no sistema
                String alterar = "Tem certeza de que deseja alterar o registro?";
                int opcao_escolhida = JOptionPane.showConfirmDialog(null, alterar, "Exclusão ", JOptionPane.YES_OPTION);
                if (opcao_escolhida == JOptionPane.YES_OPTION) {
                    relato.setIdrel(Integer.parseInt(tf_codigo.getText()));
                    relato.setModulo((Modulo) cb_modulo.getSelectedItem());
                    relato.setNomeobjeto(tf_classeObjeto.getSelectedText());
                    relato.setCasoteste(tf_casoTeste.getText());
                    relato.setPrioridade(Integer.parseInt(cb_prioridade.getSelectedItem().toString()));
                    relato.setPassos(tf_passos.getText());
                    relato.setRelato(tf_Relato.getText());
                    relato.setCategoriaerro((Categoria) cb_categoria.getSelectedItem());
                    relato.setSituacao(cb_status.getSelectedItem().toString());
                    relato.setDesenvolvedor((Desenvolvedor) cb_desenvolvedor.getSelectedItem());
                    relato.setDtabertura(tf_DTAbertura.getText());
                    relato.setDtfechamento(tf_DTFech.getText());
                    DAO objdesenvolvedor = new DAO(relato);
                    objdesenvolvedor.insere();
                    preencherJtableRelatos();
                }
     //           confirma();

            }
            //   preencherJtableModulos();*/
        } catch (HeadlessException | NumberFormatException erro) {
            System.out.println("Erro: " + erro);
        }
    }//GEN-LAST:event_btSalvarActionPerformed

    private void btNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btNovoActionPerformed

        exibeOcultaCampos();
        limpaCampos();
    }//GEN-LAST:event_btNovoActionPerformed

    private void tf_codigoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tf_codigoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tf_codigoActionPerformed

    private void cb_statusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cb_statusActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cb_statusActionPerformed

    /**
     */
    public static RelatoView instance;

    public static void main(String args[]) {
        RelatoView.getInstance();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel Painel_incluirRelato;
    private javax.swing.JButton btAbrir;
    private javax.swing.JButton btAnexar;
    private javax.swing.JButton btExcluir;
    private javax.swing.JButton btNovo;
    private javax.swing.JButton btSalvar;
    private javax.swing.JButton btTodos;
    private javax.swing.JComboBox cb_categoria;
    private javax.swing.JComboBox cb_desenvolvedor;
    private javax.swing.JComboBox cb_modulo;
    private javax.swing.JComboBox cb_prioridade;
    private javax.swing.JComboBox cb_selecProjeto;
    private javax.swing.JComboBox cb_status;
    private javax.swing.JButton jButton4;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel_Menu;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTable jtab_Anexos;
    private javax.swing.JTable jtab_Relatos;
    private javax.swing.JLabel lb_Relato;
    private javax.swing.JLabel lb_desenvolvedor;
    private javax.swing.JLabel lb_solucao;
    private javax.swing.JTextField tf_DTAbertura;
    private javax.swing.JTextField tf_DTFech;
    private javax.swing.JTextField tf_Relato;
    private javax.swing.JTextField tf_casoTeste;
    private javax.swing.JTextField tf_classeObjeto;
    private javax.swing.JTextField tf_codigo;
    private javax.swing.JTextField tf_passos;
    // End of variables declaration//GEN-END:variables

    public static RelatoView getInstance() {
        if (instance == null) {
            instance = new RelatoView();
        }
        return instance;
    }
//Popula a combobox Projetos com os projetos que possuem módulos cadastrados

    public void popularComboProj() {
        Session sessao = HibernateUtil.getSessionFactory().openSession();

// Popular combobox com todos os Projetos : Administrador
        if (LoginView.d.getPerfil().equals("Administrador")) {
            //       JOptionPane.showMessageDialog(null, "Administrador");
            try {
                Criteria c = sessao.createCriteria(Participa.class, "participa");
                c.createAlias("participa.projeto", "projeto"); // inner join by default
                c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
                List<Participa> listaParticipa = c.list();
                List<Projeto> projetos = new ArrayList<>();
                for (Participa p : listaParticipa) {
                    projetos.add(p.getProjeto());
                }
                List listaDistinct = new ArrayList(new HashSet(projetos));
                ArrayListComboBoxModel modelolista = new ArrayListComboBoxModel(listaDistinct);
                cb_selecProjeto.setModel(modelolista);
            } catch (HibernateException e) {
                JOptionPane.showMessageDialog(null, e);
            }

// Popular combobox com todos os projetos onte participa : Usuário
        } else if (LoginView.d.getPerfil().equals("Usuário")) {
            //     JOptionPane.showMessageDialog(null, "Usuário");
            try {
                Criteria c = sessao.createCriteria(Participa.class, "participa");
                c.createAlias("participa.projeto", "projeto"); // inner join by default
                c.createAlias("projeto.modulo", "modulo");
                c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
                List<Participa> listaParticipa = c.list();
                List<Projeto> projetos = new ArrayList<>();
                for (Participa p : listaParticipa) {
                    if (p.getDesenvolvedor().getIddes() == LoginView.d.getIddes()) {
                        projetos.add(p.getProjeto());
                    }
                }

                ArrayListComboBoxModel modelolista = new ArrayListComboBoxModel(projetos);

                cb_selecProjeto.setModel(modelolista);

            } catch (HibernateException e) {
                JOptionPane.showMessageDialog(null, e);
            }

        }

        sessao.close();
    }

    public void popularCombobox() {
        //Popular todas as comboboxes com exceção da combobox Projeto
        Session sessao = HibernateUtil.getSessionFactory().openSession();
        if (cb_selecProjeto.getSelectedIndex() == -1) {
            lista_modulo = sessao.createQuery("from Modulo").list();
            ArrayListComboBoxModel modelolista = new ArrayListComboBoxModel(lista_modulo);
            cb_modulo.setModel(modelolista);

        } else {
            // Popular combobox modulo conforme projeto selecionado
            lista_modulo = sessao.createQuery("from Modulo where projeto = " + projetosel.getIdproj()).list();
            ArrayListComboBoxModel modelolista = new ArrayListComboBoxModel(lista_modulo);
            cb_modulo.setModel(modelolista);
        }

        // Popular combobox categoria conforme projeto selecionado
        List<Categoria> lista_categoria = new ArrayList();
        lista_categoria = sessao.createQuery("from Categoria order by categoria").list();
        ArrayListComboBoxModel modelolista = new ArrayListComboBoxModel(lista_categoria);
        cb_categoria.setModel(modelolista);

        // Popular combobox desenvolvedor conforme projeto selecionado
        try {
            List<Desenvolvedor> d = new ArrayList<Desenvolvedor>();
            Criteria criteria = sessao.createCriteria(Participa.class);
            criteria.createAlias("desenvolvedor", "desenvolvedor");
            criteria.createAlias("projeto", "projeto");
            criteria.createAlias("funcao", "funcao");
            criteria.add(Restrictions.eq("projeto", cb_selecProjeto.getSelectedItem()));
            List<Participa> p = criteria.list();

            try {
                for (Participa c : p) {
                    d.add((Desenvolvedor) c.getDesenvolvedor());
                }
            } catch (HeadlessException e) {
                System.out.println(e);
            }
            modelolista = new ArrayListComboBoxModel(d);
            cb_desenvolvedor.setModel(modelolista);
        } catch (HibernateException e) {
            JOptionPane.showMessageDialog(null, e);
        }

        ArrayList lista_prioridade = new ArrayList();
        lista_prioridade.add("1");
        lista_prioridade.add("2");
        lista_prioridade.add("3");
        lista_prioridade.add("4");

        modelolista = new ArrayListComboBoxModel(lista_prioridade);
        cb_prioridade.setModel(modelolista);

        sessao.close();
    }

    private void desativaBotoes() {
        btNovo.setEnabled(false);
        btSalvar.setEnabled(false);
        btExcluir.setEnabled(false);
        btAbrir.setEnabled(false);
        btAnexar.setEnabled(false);

    }

    private void ativaBotNew() {
        btNovo.setEnabled(true);
    }

    private void ativaBotExist() {
        btAbrir.setEnabled(true);
        btExcluir.setEnabled(true);
        btSalvar.setEnabled(true);
        btAnexar.setEnabled(true);
    }

    private void exibeOcultaCampos() {
        if (Painel_incluirRelato.isVisible() && tf_codigo.equals("")) {
            Painel_incluirRelato.setVisible(false);
            cb_modulo.requestFocus();
            projetosel = (Projeto) cb_selecProjeto.getSelectedItem();
        } else {
            Painel_incluirRelato.setVisible(true);
            cb_modulo.requestFocus();
            jScrollPane1.setSize(1000, 1000);
            popularCombobox();
        }

    }

    public void preencherJtableRelatos() {//xyz
        modelrel.setEditableDefault(true);
        modelrel.clear();
        limpaCampos();
        Session sessao = HibernateUtil.getSessionFactory().openSession();

        if (login.d.getPerfil().toString().equals("Administrador")) {
            lista_relato = sessao.createQuery("from Relato order by idrel").list();
        } else {
            lista_relato = sessao.createQuery("from Relato where desenvolvedor =" + login.d.getIddes() + "order by idrel").list();
        }
        if (cb_selecProjeto.getSelectedIndex() == -1) {
            try {

                for (int i = 0; i < lista_relato.size(); i++) {
                    Relato relato = lista_relato.get(i);
                    modelrel.add(relato);
                }
                sessao.close();
                desativaBotoes();
            } catch (HibernateException erro) {
                JOptionPane.showMessageDialog(null, "Erro na insersão : " + erro);
            }
        } else {
            try {
                lista_relato = sessao.createQuery("from Relato where relato.modulo.projeto.idproj = " + projetosel.getIdproj()).list();
                for (int i = 0; i < lista_relato.size(); i++) {
                    Relato relato = lista_relato.get(i);
                    modelrel.add(relato);
                }
             //   JOptionPane.showMessageDialog(null, modelrel);
                sessao.close();
                ativaBotNew();
            } catch (HibernateException erro) {
                JOptionPane.showMessageDialog(null, "Erro na insersão : " + erro);
            }
        }
        jtab_Relatos.setModel(modelrel);

            jtab_Relatos.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        jScrollPane1.setViewportView(jtab_Relatos);
        jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    }
// Lista documentos na jtable Anexos

    public void preencherJtableAnexos() {
        modelanx.setEditableDefault(true);
        modelanx.clear();
        //  limpaCampos();
        try {
            Session sessao = HibernateUtil.getSessionFactory().openSession();
            List<Anexo> lista_anexo = new ArrayList();
            lista_anexo = sessao.createQuery("from Anexo where relato.idrel = " + tf_codigo.getText()).list();

            if (lista_anexo.isEmpty()) {
                jTabbedPane1.setEnabledAt(1, false);
            } else {

                for (int i = 0; i < lista_anexo.size(); i++) {
                    Anexo anexo = lista_anexo.get(i);
                    modelanx.add(anexo);
                }
                jTabbedPane1.setEnabledAt(1, true);
                jtab_Anexos.setModel(modelanx);
            }

            sessao.close();
        } catch (HeadlessException | HibernateException erro) {
            JOptionPane.showMessageDialog(null, "Erro na insersão : " + erro);
        }
    }

    public void limpaCampos() {

        tf_codigo.setText("");

        cb_modulo.setSelectedIndex(-1);
        tf_classeObjeto.setText("");
        tf_casoTeste.setText("");
        tf_passos.setText("");
        tf_Relato.setText("");
        cb_prioridade.setSelectedIndex(-1);
        cb_categoria.setSelectedIndex(-1);
        cb_status.setSelectedIndex(-1);
        cb_desenvolvedor.setSelectedIndex(-1);
        tf_DTAbertura.setText("");
        tf_DTFech.setText("");
    }

    public void confirma() {
        JOptionPane.showMessageDialog(null, "Operação executada com sucesso");
    }

    @Override
    public void actionPerformed(ActionEvent event) {
        JMenuItem menu = (JMenuItem) event.getSource();
        if (menu == menuItemView) {
            visualizarLinha();
        } else if (menu == menuItemRemove) {
            removerLinha();
        }
    }
// Visualizar documento selecionado na jtable Anexos

    private void visualizarLinha() {
        try {
            Anexo objanexo = modelanx.getValue(jtab_Anexos.getSelectedRow()); //Linha do registro
            //        JOptionPane.showMessageDialog(null, objanexo.getCaminho());
            File file = new File(objanexo.getCaminho());
            //         Anexar anexo = new Anexar();
            JOptionPane.showMessageDialog(null, file.getAbsolutePath());
            try {
                java.awt.Desktop.getDesktop().open(new File(file.getAbsolutePath()));
            } catch (IOException ex) {
                Logger.getLogger(RelatoView.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (HeadlessException e) {
            JOptionPane.showMessageDialog(null, e);
        }
    }
// Remover documento selecionado na jtable Anexos

    private void removerLinha() {
        try {
            Anexo objanexo = modelanx.getValue(jtab_Anexos.getSelectedRow()); //Linha do registro
            File file = new File(objanexo.getCaminho());
            Anexar anexo = new Anexar();
            anexo.deletarFile(file);
            anexo.deletarAnexo(objanexo);
            preencherJtableAnexos();
        } catch (HeadlessException e) {
            JOptionPane.showMessageDialog(null, e);
        }
    }

}
